import 'package:fate_blind_box/theme/theme_color.dart';
import 'package:fate_blind_box/utils/common_widget.dart';
import 'package:fate_blind_box/utils/loading.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ComplaintListSubmitPage extends StatefulWidget {
  const ComplaintListSubmitPage({Key? key}) : super(key: key);

  @override
  State<ComplaintListSubmitPage> createState() =>
      _ComplaintListSubmitPageState();
}

class _ComplaintListSubmitPageState extends State<ComplaintListSubmitPage> {
  List<String> list = [
    '存在赌博行为',
    '存在欺诈行为',
    '发布不适当的信息',
    '传播谣言信息',
  ];
  TextEditingController submitController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return AppWidget.navTitleBar(
      title: '选择投诉原因',
      bgColor: ThemeColor.sendMsgColor,
      childWidget: Column(
        children: [
          Expanded(
            child: ListView.builder(
                itemCount: list.length,
                itemBuilder: (BuildContext context, int index) {
                  return index == (list.length - 1)
                      ? Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            const SizedBox(
                              height: 20,
                            ),
                            const Padding(
                              padding: EdgeInsets.only(left: 10),
                              child: Text(
                                '备注：',
                                style: TextStyle(fontSize: 14),
                              ),
                            ),
                            const SizedBox(
                              height: 20,
                            ),
                            Container(
                              height: 100,
                              margin: const EdgeInsets.only(
                                  left: 10, right: 10, top: 0),
                              padding: const EdgeInsets.only(
                                  top: 15, bottom: 15, left: 5, right: 5),
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(4),
                              ),
                              child: TextField(
                                maxLines: 1,
                                controller: submitController,
                                obscureText: false,
                                keyboardType: TextInputType.text,
                                cursorColor: ThemeColor.sendMsgTextColor,
                                style: TextStyle(
                                    fontSize: 16, color: ThemeColor.textColor),
                                decoration: const InputDecoration(
                                  hintText: "请输入投诉原因",
                                  isCollapsed: true,
                                  border: InputBorder.none,
                                ),
                              ),
                            ),
                          ],
                        )
                      : GestureDetector(
                          onTap: () {
                            backToCommonPage();
                          },
                          child: Container(
                            color: Colors.white,
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                const SizedBox(
                                  height: 14,
                                ),
                                Padding(
                                  padding: const EdgeInsets.symmetric(
                                      horizontal: 15),
                                  child: Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: [
                                      Text(
                                        list[index],
                                        style: const TextStyle(
                                            fontSize: 14, color: Colors.black),
                                      ),
                                      const Icon(
                                        Icons.arrow_forward_ios_rounded,
                                        color: Color(0xFFB5B5B5),
                                        size: 20,
                                      )
                                    ],
                                  ),
                                ),
                                const SizedBox(
                                  height: 24,
                                ),
                                Container(
                                  height: 0.5,
                                  color: ThemeColor.lineColor,
                                ),
                              ],
                            ),
                          ),
                        );
                }),
          ),
          GestureDetector(
            onTap: () {
              backToFrontPage();
            },
            child: Container(
              margin: const EdgeInsets.only(left: 20, right: 20, bottom: 20),
              padding: const EdgeInsets.symmetric(vertical: 15),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                color: ThemeColor.appColor,
              ),
              child: const Text(
                '提交',
                style: TextStyle(color: Colors.white, fontSize: 18),
              ),
            ),
          ),
        ],
      ),
    );
  }

  void backToFrontPage() {
    if(submitController.text.isEmpty){
      toast('请输入投诉内容');
      return;
    }
     backToCommonPage();
  }

  void backToCommonPage(){
    toast('已收到您的反馈，平台会及时处理');
    Get.back();
  }
}
